package com.zhxh.nzpos.stock;

import java.util.ArrayList;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.zhxh.nzpos.R;
import com.zhxh.nzpos.model.Stock;

public class StockListAdapter extends BaseAdapter {

	private LayoutInflater inflater;
	private ArrayList<Stock> stocks;
	
	public StockListAdapter(LayoutInflater inflater, ArrayList<Stock> stocks) {
		this.inflater = inflater;
		this.stocks = stocks;
	}
	
	@Override
	public int getCount() {
		return stocks.size();
	}

	@Override
	public Object getItem(int position) {
		return stocks.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		if (convertView == null) {
			convertView = inflater.inflate(R.layout.stock_manage_list_item, null);
			holder = new ViewHolder();
			holder.name = (TextView) convertView.findViewById(R.id.goods_name_tv);
			holder.inputDate = (TextView) convertView.findViewById(R.id.input_date_tv);
			holder.number = (TextView) convertView.findViewById(R.id.goods_number_tv);
			holder.supplier = (TextView) convertView.findViewById(R.id.goods_supplier_tv);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		
		Stock stock = stocks.get(position);
		if (stock != null) {
			holder.name.setText(stock.getGoodsName());
			holder.inputDate.setText(stock.getStockDate());
			holder.number.setText(""+stock.getCount());
//			holder.supplier.setText(stock.getUnit());
		}
		return convertView;
	}

	static class ViewHolder {
		TextView name;
		TextView inputDate;
		TextView number;
		TextView supplier;
	}
}
